// pages/order/index.js
import ddt from '../../api/axios.js'
import time from '../../utils/util.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    value: '',
    active: 0,
    orderinfo: '',
    userinfo:''
  },
  onChange(event) {
    console.log(event)
    if(event.detail.name == 5){
      wx.showModal({
        title:'提示',
        content:'请致电服务电话：136545,或扫描二维码',
        showCancel:false
      })
    }
    this.setData({
      active: event.detail.name
    })
    this.info(event.detail.name)
  },
  tuik(){
 
  },
  info(typeone) {
    var type =''
    if(typeone.detail == undefined){
       type = typeone
    }else{
      type = typeone.currentTarget.dataset.type
    }
    var sta = ''
    if(type== 0 ){
      sta = 1
    }else if(type== 2){
      sta = 2
    }else if(type== 3){
      sta = 5
    }else if(type== 4){
      sta = 6
    }
   if(type== 1){
    this.setData({
      orderinfo: ''
    })
   }else{
    ddt('get', '/api/user/order' , {
      page:1,
      state: sta,
    }).then(res => {     
      if( res.data.data==''){
        this.setData({
          orderinfo:[]
        })
      }else{
        this.setData({
          orderinfo: res.data.data.order_info.map(v=>{
            return {
              ...v,
              time:time.formatTime(new Date(v.orderat*1000))
            }
          })
        })
      }

    })
   }
   
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
onTabItemTap:function(item){

},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      this.getTabBar().setData({
        selected: 1
      })
      if (wx.getStorageSync('userinfo') == '') {
        wx.showModal({
          title: '提示',
          content: '是否前往登陆',
          success (res) {
            if (res.confirm) {
              wx.navigateTo({
                url: '../login/login',
              })
            }
          }
        })
      }
    }
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      userinfo:wx.getStorageSync('userinfo')
    })
    this.info(0)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})